package com.nettyrpc.utils;

import com.nettyrpc.bean.CglibHandlerAdapter;
import com.nettyrpc.bean.InvokeHandler;
import com.nettyrpc.bean.JdkProxyHandlerAdapter;
import com.nettyrpc.protocol.RpcRequest;


public class ReflectUtils {

    private ReflectUtils() {}

    /**
     * JDK Proxy
     * @param serviceBean
     * @param request
     * @return
     */
    public static Object jdkProxyInvoke(Object serviceBean, RpcRequest request) throws Throwable {
        InvokeHandler invokeHandler = new JdkProxyHandlerAdapter();
        return invokeHandler.handle(serviceBean, request);
    }

    /**
     * CgLib Enhance
     * @param serviceBean
     * @param request
     * @return
     * @throws Throwable
     */
    public static Object cglibInvoke(Object serviceBean, RpcRequest request) throws Throwable {
        InvokeHandler invokeHandler = new CglibHandlerAdapter();
        return invokeHandler.handle(serviceBean, request);
    }
}
